<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>圆球游戏</title>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <style>
        body {
            margin: 0;
            padding: 0;
        }
        .container {
            margin: 0;
            padding: 0;
            position: absolute;
            width: 440px;
            height: 440px;
            background-color: blanchedalmond;
            display: inline;
        }
        .ball {
            position:absolute;
            width: 60px;
            height: 60px;
            left:100px;
            top:100px;
            background-color: red;
            border-radius: 30px;
            z-index:100
        }
    </style>
</head>
<body>
    <div id="Application">
        <!-- 外层的div为游戏面板，小球需要在此容器中移动 -->
        <div class="container" @mousemove.stop="move">
            <!-- 此div元素表示小球 -->
            <div class="ball" :style="{left: offsetX+'px', top:offsetY+'px'}">
            </div>
        </div>
    </div>
    <script>
        const {createApp, ref} = Vue
        const config = {
            setup() {
                const offsetX = ref(0)
                const offsetY = ref(0)
                const move = (event) => {
                   if (event.clientX + 30 > 440) {
                        offsetX.value = 440 - 60
                   } else if (event.clientX - 30 < 0) {
                        offsetX.value = 0
                   } else {
                        offsetX.value = event.clientX - 30
                   }
                   if (event.clientY + 30 > 440) {
                        offsetY.value = 440 - 60
                   } else if (event.clientY - 30 < 0) {
                        offsetY.value = 0
                   } else {
                        offsetY.value = event.clientY - 30
                   }
               }
               return {offsetX, offsetY, move}
            }
        }
        createApp(config).mount("#Application") 
    </script>
</body>
</html>